package com.consumer;

import com.constant.TopicConstant;
import com.pool.TreadPoolUtils;
import com.utils.MailUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class MailMessageConsumer {

    @Autowired
    private MailUtils mailUtils;

    @KafkaListener(topics = TopicConstant.MAIL_MESSAGE_TOPIC, groupId = "mail_message")
    public void listen(ConsumerRecord<String, String> record) {
        TreadPoolUtils.getTokenConsumerPool().execute(() -> {
            String mail = record.key();
            String password = record.value();

            String content = "[汽车充电桩管理系统]" + " 登录所需的密码，不要和其他人分享";
            String msg = "您已经通过管理员注册维修员账号成功，这是为您首次登录生成的默认密码：" + password + "，后续可自行修改";
            mailUtils.sendMail(mail,content,msg);

        });
    }


}
